<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: 贾振鹏
  Date: 2021/6/2
  Time: 16:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="${css}/pintuer.css">
    <link rel="stylesheet" href="${css}/admin.css">
    <script src="${js}/jquery.js"></script>
    <script src="${js}/pintuer.js"></script>
</head>
<body>
<form method="post" action="${root}/admin/news/list" id="listform">
    <input type="hidden" id="currentPage" name="currentPage" value="${pv.pageIndex}">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
        <div class="padding border-bottom">
            <ul class="search" style="padding-left:10px;">
                <li>标题: <input type="text" value="${sv.title}" name="title" class="input" style="width:100px; line-height:17px;display:inline-block">
                    &nbsp;&nbsp;
                    作者来源:
                    <select id="author" name="author" class="input" style="width:100px; line-height:17px;display:inline-block">
                        <option value="">请选择</option>
                        <option value="网站自创">网站自创</option>
                        <option value="新华网转载">新华网转载</option>
                        <option value="央视网转载">央视网转载</option>
                        <option value="人民网转载">人民网转载</option>
                        <option value="新浪网转载">新浪网转载</option>
                        <option value="搜狐网转载">搜狐网转载</option>
                    </select>
                    &nbsp;&nbsp;
                    新闻类型:
                    <select id="category" name="category" class="input" style="width:70px; line-height:17px;display:inline-block">
                        <option value="">请选择</option>
                        <c:forEach items="${categoryList}" var="type" >
                            <option value="${type.category}">${type.category}</option>
                        </c:forEach>
                    </select>
                    &nbsp;&nbsp;
                    新闻状态：
                    <select id="status" name="status" class="input" style="width:80px; line-height:17px;display:inline-block">
                        <option value="-1">请选择</option>
                            <option value="0">显示</option>
                            <option value="1">审核</option>
                            <option value="2">删除</option>
                    </select>
                </li>
                <if condition="$iscid eq 1">
                    <br/>
                    <li>
                        时间区间：<input type="date" name="minTime" class="input" value="${param.minTime}">
                        -
                        <input type="date" name="maxTime" class="input" value="${param.maxTime}">
                    </li>
                </if>
                <li>
                    <input type="submit" class="button border-main icon-search" value="搜索" />
                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th width="100" style="text-align:left; padding-left:20px;">序号</th>
                <th width="10%">标题</th>
                <th>图片</th>
                <th>分类名称</th>
                <th width="10%">更新时间</th>
                <th width="310">操作</th>
            </tr>
                <tbody>
                <c:forEach items="${pv.objList}" var="news" varStatus="v">

                <tr>
                    <td style="text-align:left; padding-left:20px;">
                      ${v.count}  </td>
                    <td><a href="${root}/admin/news/editview?id=${news.id}">${news.title}</a></td>
                    <td width="10%"><img src="${news.image}" alt="" width="70" height="50" /></td>
                    <td><font color="#00CC99">${news.category}</font></td>
                    <td><fmt:formatDate value="${news.createdate}" pattern="yyyy-MM-dd HH:mm"/></td>

                    <td>
                        <div class="button-group">
                            <c:if test="${news.status ne 2}">
                                <a class="button border-red delNews" name="${news.id}" href="javascript:void(0)" ><span class="icon-trash-o"></span> 删除</a>
                                <input type="hidden" value="${news.istop}">
                            </c:if>
                            <c:if test="${news.status eq 2}">
                                已删除
                            </c:if>
                        </div>
                    </td>
                </tr>
                </c:forEach>
                </tbody>
                <tr>
                    <td colspan="8">
                        <div class="pagelist">
                            <c:forEach begin="1" end="${pv.pageTotal}" var="i">
                                <c:if test="${pv.pageIndex ne 1}">
                                    <a href="javascript:;" onclick="changePage(1)">第一页</a>
                                    <a href="javascript:;" onclick="changePage(${pv.pageIndex-1})">上一页</a>
                                </c:if>
                                <c:choose>
                                    <c:when test="${pv.pageIndex eq i}">
                                        <span class="current">${i}</span>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="javascript:;" onclick="changePage(${i})">${i}</a>
                                    </c:otherwise>
                                </c:choose>
                                <c:if test="${pv.pageIndex ne pv.pageTotal}">
                                    <a href="javascript:;" onclick="changePage(${pv.pageIndex+1})">下一页</a>
                                    <a href="javascript:;" onclick="changePage(${pv.pageTotal})">尾页</a>
                                </c:if>
                            </c:forEach>
                        </div>
                    </td>
                </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    $(function () {
        //数据回显
        $("#author").find("option[value='${sv.author}']").attr("selected",'selected');
        $("#category").find("option[value='${sv.category}']").attr("selected",'selected');
        $("#status").find("option[value='${sv.status}']").attr("selected",'selected');

        //修改页码
        function changePage(page){
            $("#currentPage").val(page);
            $("#listform").submit();
        }
        
        //删除
        $(".delNews").click(function () {
            if(!confirm("是否确认删除？")){
                return;
            }
            var id = $(this).attr("name");
            var istop = $(this).next().val();
            var target = $(this);
            var obj = $(this).parent();
            $.get("${root}/admin/news/delete",
                {"id":id,"istop":istop},
            function (res) {
                if(res.code==200){
                    target.remove();
                    obj.append("已删除")
                }else {
                    alert("系统繁忙。。稍后再试。。")
                }
            });


        })

    })



</script>
</body>
</html>
